import cv2
import math
import numpy as np
from numpy.lib.function_base import copy
flag = False
x1=y1=0
#新建画布
maskDIY= np.zeros((200,200),np.uint8)
#画圆
cv2.circle(maskDIY,(100,100),50,255,-1, cv2.LINE_AA)

#鼠标点击函数
def screenShot(event,x,y,flags,param):
  global x1,y1,flag,img,temp,maskDIY
  if event==cv2.EVENT_LBUTTONDOWN: #鼠标左键按下
    flag = True #表示当前鼠标左键是按下的
    img = temp.copy()#原图复制(把绘制的矩形清空)
    rio_front=img[y-100:y+100,x-100:x+100]
    big2=img[y-50:y+50,x-50:x+50]
    cv2.imshow("small",big2)
    big3=cv2.resize(big2,(200,200),interpolation=cv2.INTER_AREA)
    rio_big=big3
    
    #cv2.imshow("rio_front",rio_front)
    cv2.imshow("rio_big",rio_big)
    cv2.copyTo(rio_big,mask=maskDIY,dst=rio_front)
    cv2.circle(img,(x,y),50,(0,0,0),2, cv2.LINE_AA)
  elif event==cv2.EVENT_MOUSEMOVE: #鼠标移动
    if(flag):
       img = temp.copy()#原图复制(把绘制的矩形清空)
       rio_front=img[y-100:y+100,x-100:x+100]
    big2=img[y-50:y+50,x-50:x+50]
    cv2.imshow("small",big2)
    big3=cv2.resize(big2,(200,200),interpolation=cv2.INTER_AREA)
    rio_big=big3
    #cv2.imshow("rio_front",rio_front)
    cv2.imshow("rio_big",rio_big)
    cv2.copyTo(rio_big,mask=maskDIY,dst=rio_front)
    cv2.circle(img,(x,y),50,(0,0,0),2, cv2.LINE_AA)
    #cv2.imshow("img",img)
  

  elif event==cv2.EVENT_LBUTTONUP: #鼠标左键弹起
      flag = False            
      img=temp;     



front=cv2.imread("images/a.jpg")

img=front.copy()
temp=img.copy()


cv2.namedWindow('screenShot')
cv2.setMouseCallback('screenShot',screenShot)

while(1):
  cv2.imshow('screenShot',img)
  if cv2.waitKey(1)&0xFF==27: #Esc按下退出
    break
cv2.destroyAllWindows()





cv2.waitKey(0)





